﻿package base.component
{
    import com.sh.game.display.*;
    import com.sh.game.loader.*;
    import flash.display.*;
    import plugin.component.view.enum.*;

    public class ActorMovie extends Sprite
    {
        private var _model:String;
        public var fps:int = 0;
        public var standX:int = 0;
        public var standY:int = 0;
        private var _weaponEffectModel:String = null;
        private var _weaponEff:XMLMovieClip;
        private var _weaponEffDic:Object;
        private var _weaponEfftype:int = 1;
        private var _effScale:Number = 1;
        public var totalDir:int = 0;
        private var _mc:BMDMovieClip;
        private var _effType:int = 1;
        private var arm:Object;
        private var _sourceName:int = 0;
        private var _disposed:Boolean = false;
        private var _completeFunc:Function;
        private var _interval:int = 15;

        public function ActorMovie(param1:Object, param2:Function = null)
        {
            this.arm = param1;
            var _loc_3:* = param1.model.split("/");
            if (_loc_3.length == 2)
            {
                this._model = _loc_3[1];
            }
            else
            {
                this._model = param1.model;
            }
            this._effType = param1.efftype;
            var _loc_4:String = "assets/models/show/";
            SWFActionLoader2.instance.load(_loc_4, this.onComplete, this._model, ActionType.SHOWSTAND, true, 4);
            this.mouseChildren = false;
            this.mouseEnabled = false;
            this._completeFunc = param2;
            return;
        }// end function

        private function onComplete(param1:ActionAssets, param2:String, param3:int) : void
        {
            this._sourceName = int(param2);
            if (param1 == null)
            {
                return;
            }
            if (this._model == null)
            {
                SWFActionLoader2.instance.unload(this._sourceName, true);
                return;
            }
            if (this._mc)
            {
                this._mc.dispose();
            }
            this._mc = null;
            this._mc = new BMDMovieClip(param1.bmps, param1.frameSet);
            this.addChild(this._mc);
            this._mc.pivotX = this.standX;
            this._mc.pivotY = this.standY;
            this._mc.interval = 1000 / this._interval;
            this._mc.play();
            if (this._completeFunc != null)
            {
                this._completeFunc();
            }
            return;
        }// end function

        public function get interval() : int
        {
            return this._interval;
        }// end function

        public function set interval(param1:int) : void
        {
            this._interval = param1;
            if (this._mc)
            {
                this._mc.interval = this._interval;
            }
            return;
        }// end function

        public function getArmEffect(param1:Object) : String
        {
            var _loc_2:Array = null;
            if (param1.effect && param1.effect != "")
            {
                _loc_2 = String(param1.effect).split("/");
                if (_loc_2.length == 2)
                {
                    if (param1.superlevel == 10)
                    {
                        if (_loc_2[1] != "0")
                        {
                            return _loc_2[1];
                        }
                        return null;
                    }
                    else if (!param1.hasOwnProperty("superlevel") || param1.superlevel >= 0)
                    {
                        if (_loc_2[0] != "0")
                        {
                            return _loc_2[0];
                        }
                        return null;
                    }
                    if (param1.yitian == 1)
                    {
                        return _loc_2[0];
                    }
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
            return null;
        }// end function

        private function onComplete2(param1:ActionReader, param2:int, param3:Boolean, param4:int) : void
        {
            return;
        }// end function

        private function armEffCfgLoaded(param1:Object) : void
        {
            this._weaponEffDic = param1;
            this.locationArmEff();
            return;
        }// end function

        private function locationArmEff(param1:int = -1) : void
        {
            var _loc_3:Object = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_2:* = ActionType.SHOWSTAND;
            if (this._weaponEffDic && this._mc && this._weaponEff)
            {
                _loc_3 = this._weaponEffDic[_loc_2 + "_" + 4 + "_" + this._mc.frame];
                if (_loc_3)
                {
                    _loc_4 = 1;
                    if (this._mc.scaleX == -1)
                    {
                        _loc_4 = -1;
                    }
                    this._weaponEff.x = int(_loc_3.x) * _loc_4;
                    this._weaponEff.y = int(_loc_3.y);
                    if (this._weaponEff)
                    {
                        this._weaponEff.scaleX = Number(_loc_3.scaleX) * _loc_4 * this._effScale;
                        this._weaponEff.scaleY = _loc_3.scaleY * this._effScale;
                        _loc_5 = 0;
                        if (_loc_4 < 0)
                        {
                            _loc_5 = -_loc_3.rotation;
                        }
                        else
                        {
                            _loc_5 = _loc_3.rotation;
                        }
                        this._weaponEff.rotation = _loc_5;
                    }
                }
            }
            else if (!this._mc && this._weaponEff)
            {
                this._weaponEff.scaleX = 0;
                this._weaponEff.scaleY = 0;
            }
            return;
        }// end function

        public function restartMc() : void
        {
            if (this._mc)
            {
                this._mc.gotoAndPlay(0);
            }
            return;
        }// end function

        public function dispose() : void
        {
            this._disposed = true;
            if (this._model == null)
            {
                return;
            }
            if (this._weaponEff && this._mc.parent)
            {
                this._weaponEff.parent.removeChild(this._weaponEff);
            }
            if (this._weaponEff)
            {
                this._weaponEff.dispose();
            }
            this._weaponEff = null;
            this._weaponEffDic = null;
            this._weaponEffectModel = null;
            if (this._sourceName)
            {
                SWFActionLoader2.instance.unload(this._sourceName, true);
            }
            this._sourceName = 0;
            this._model = null;
            this.fps = 0;
            this.standX = 0;
            this.standY = 0;
            this.totalDir = 0;
            if (this._mc && this._mc.parent)
            {
                this._mc.parent.removeChild(this._mc);
            }
            if (this._mc)
            {
                this._mc.dispose();
            }
            this._mc = null;
            return;
        }// end function

    }
}
